<template>
    <div class="loading-screen">
        <div class="loading-container">
            <!-- 主标题 -->
            <div class="main-title">
                <span class="title-text">基层社区监测防控平台</span>
                <span class="title-subtitle">COMMUNITY MONITORING PLATFORM</span>
            </div>

            <!-- 加载动画 -->
            <div class="loading-animation">
                <div class="loading-dots">
                    <div class="dot" v-for="i in 3" :key="i" :style="{ animationDelay: `${i * 0.2}s` }"></div>
                </div>
                <div class="loading-text">系统加载中</div>
            </div>

            <!-- 装饰元素 -->
            <div class="decorative-elements">
                <div class="corner top-left"></div>
                <div class="corner top-right"></div>
                <div class="corner bottom-left"></div>
                <div class="corner bottom-right"></div>
            </div>

            <!-- 进度条 -->
            <div class="progress-container">
                <div class="progress-bar" :style="{ width: progress + '%' }"></div>
                <div class="progress-text">{{ Math.round(progress) }}%</div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'LoadingScreen',
    data() {
        return {
            progress: 0
        }
    },
    mounted() {
        this.simulateProgress()
    },
    methods: {
        simulateProgress() {
            const interval = setInterval(() => {
                this.progress += Math.random() * 15
                if (this.progress >= 100) {
                    this.progress = 100
                    clearInterval(interval)
                    // 延迟隐藏加载界面
                    setTimeout(() => {
                        this.$emit('loading-complete')
                    }, 500)
                }
            }, 200)
        }
    }
}
</script>

<style lang="scss" scoped>
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #0c1426 0%, #1a2332 50%, #0c1426 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    overflow: hidden;

    &::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background:
            radial-gradient(circle at 20% 20%, rgba(64, 156, 255, 0.1) 0%, transparent 50%),
            radial-gradient(circle at 80% 80%, rgba(64, 156, 255, 0.1) 0%, transparent 50%);
        animation: backgroundShift 8s ease-in-out infinite;
    }
}

.loading-container {
    text-align: center;
    position: relative;
    z-index: 2;
}

.main-title {
    margin-bottom: 60px;

    .title-text {
        display: block;
        font-size: 48px;
        font-weight: 300;
        color: #ffffff;
        text-shadow: 0 0 20px rgba(64, 156, 255, 0.5);
        letter-spacing: 8px;
        margin-bottom: 10px;
        animation: titleGlow 2s ease-in-out infinite alternate;
    }

    .title-subtitle {
        display: block;
        font-size: 16px;
        color: rgba(255, 255, 255, 0.6);
        letter-spacing: 4px;
        font-weight: 200;
    }
}

.loading-animation {
    margin-bottom: 60px;

    .loading-dots {
        display: flex;
        justify-content: center;
        gap: 12px;
        margin-bottom: 20px;

        .dot {
            width: 12px;
            height: 12px;
            background: linear-gradient(45deg, #409cff, #64b5f6);
            border-radius: 50%;
            animation: dotBounce 1.4s ease-in-out infinite;
            box-shadow: 0 0 20px rgba(64, 156, 255, 0.6);
        }
    }

    .loading-text {
        color: rgba(255, 255, 255, 0.8);
        font-size: 18px;
        font-weight: 300;
        letter-spacing: 2px;
    }
}

.decorative-elements {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;

    .corner {
        position: absolute;
        width: 60px;
        height: 60px;
        border: 2px solid rgba(64, 156, 255, 0.3);

        &.top-left {
            top: 40px;
            left: 40px;
            border-right: none;
            border-bottom: none;
        }

        &.top-right {
            top: 40px;
            right: 40px;
            border-left: none;
            border-bottom: none;
        }

        &.bottom-left {
            bottom: 40px;
            left: 40px;
            border-right: none;
            border-top: none;
        }

        &.bottom-right {
            bottom: 40px;
            right: 40px;
            border-left: none;
            border-top: none;
        }
    }
}

.progress-container {
    position: relative;
    width: 300px;
    margin: 0 auto;

    .progress-bar {
        height: 4px;
        background: linear-gradient(90deg, #409cff, #64b5f6);
        border-radius: 2px;
        transition: width 0.3s ease;
        box-shadow: 0 0 10px rgba(64, 156, 255, 0.5);
    }

    .progress-text {
        position: absolute;
        top: -30px;
        right: 0;
        color: rgba(255, 255, 255, 0.7);
        font-size: 14px;
        font-weight: 300;
    }
}

// 动画定义
@keyframes titleGlow {
    0% {
        text-shadow: 0 0 20px rgba(64, 156, 255, 0.5);
    }

    100% {
        text-shadow: 0 0 30px rgba(64, 156, 255, 0.8), 0 0 40px rgba(64, 156, 255, 0.3);
    }
}

@keyframes dotBounce {

    0%,
    80%,
    100% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

@keyframes backgroundShift {

    0%,
    100% {
        opacity: 0.3;
    }

    50% {
        opacity: 0.6;
    }
}

// 响应式设计
@media (max-width: 768px) {
    .main-title .title-text {
        font-size: 36px;
        letter-spacing: 6px;
    }

    .main-title .title-subtitle {
        font-size: 14px;
        letter-spacing: 3px;
    }

    .loading-animation .loading-text {
        font-size: 16px;
    }

    .progress-container {
        width: 250px;
    }
}
</style>
